//建造者模式
#include<iostream>
#include<memory>
#include<string>
using namespace std;

//抽象产品类
class Computer
{
public:
    using ptr=shared_ptr<Computer>;
    Computer(){}
    void setboard(const string& board) {_board=board;}
    void setdisplay(const string& display) {_dispaly=display;}
    virtual void setos() {}
    void show()
    {
        cout<<"_board: "<<_board<<endl<<"_display: "<<_dispaly<<endl<<"_os: "<<_os<<endl;
    }
protected:
    string _board;
    string _dispaly;
    string _os;
};
//具体产品类
class MacBook:public Computer
{
public:
    using ptr=shared_ptr<MacBook>;
    MacBook(){}
    void setos() override
    {
        _os="Max OS X12";
    }
};
//抽象建造者类
class Builder
{
public:
    using ptr=shared_ptr<Builder>;
    Builder(){}
    virtual void buildBoard(const string&)=0;
    virtual void buildDisplay(const string&)=0;
    virtual void buildOs()=0;
    virtual Computer::ptr build()=0;
};
//具体建造者类
class MacBookBuilder:public Builder
{
public:
    using ptr=shared_ptr<MacBookBuilder>;
    MacBookBuilder():_computer(new MacBook()) {}
    void buildBoard(const string& board) override
    {
        _computer->setboard(board);
    }
    void buildDisplay(const string& display) override
    {
        _computer->setdisplay(display);
    }
    void buildOs() override
    {
        _computer->setos();
    }
    Computer::ptr build() override
    {
        return _computer;
    }
private:
    Computer::ptr _computer;
};
//指挥者类
class Director
{
public:
    Director(Builder* builder):_builder(builder) {}
    void construct(const string& board,const string& display)
    {
        _builder->buildBoard(board);
        _builder->buildDisplay(display);
        _builder->buildOs();
    }
private:
    Builder::ptr _builder;
};
int main()
{
    Builder* mac=new MacBookBuilder();
    unique_ptr<Director> director(new Director(mac));
    director->construct("英特尔主板","VOC显示屏");
    Computer::ptr computer=mac->build();
    computer->show();
    return 0;
}